package o;

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;

final class fxp implements fxg {
    public final fxw ˊ;
    public final fxi ˋ = new fxi();
    boolean ॱ;

    fxp(fxw o_fxw) {
        if (o_fxw == null) {
            throw new NullPointerException("source == null");
        }
        this.ˊ = o_fxw;
    }

    public fxi ˏ() {
        return this.ˋ;
    }

    public long ˊ(fxi o_fxi, long j) throws IOException {
        if (o_fxi == null) {
            throw new IllegalArgumentException("sink == null");
        } else if (j < 0) {
            throw new IllegalArgumentException("byteCount < 0: " + j);
        } else if (this.ॱ) {
            throw new IllegalStateException("closed");
        } else if (this.ˋ.ˎ == 0 && this.ˊ.ˊ(this.ˋ, 8192) == -1) {
            return -1;
        } else {
            return this.ˋ.ˊ(o_fxi, Math.min(j, this.ˋ.ˎ));
        }
    }

    public boolean ᐝ() throws IOException {
        if (!this.ॱ) {
            return this.ˋ.ᐝ() && this.ˊ.ˊ(this.ˋ, 8192) == -1;
        } else {
            throw new IllegalStateException("closed");
        }
    }

    public void ˎ(long j) throws IOException {
        if (!ॱ(j)) {
            throw new EOFException();
        }
    }

    public boolean ॱ(long j) throws IOException {
        if (j < 0) {
            throw new IllegalArgumentException("byteCount < 0: " + j);
        } else if (this.ॱ) {
            throw new IllegalStateException("closed");
        } else {
            while (this.ˋ.ˎ < j) {
                if (this.ˊ.ˊ(this.ˋ, 8192) == -1) {
                    return false;
                }
            }
            return true;
        }
    }

    public byte ʻ() throws IOException {
        ˎ(1);
        return this.ˋ.ʻ();
    }

    public fxh ˋ(long j) throws IOException {
        ˎ(j);
        return this.ˋ.ˋ(j);
    }

    public byte[] ʻॱ() throws IOException {
        this.ˋ.ˋ(this.ˊ);
        return this.ˋ.ʻॱ();
    }

    public byte[] ॱॱ(long j) throws IOException {
        ˎ(j);
        return this.ˋ.ॱॱ(j);
    }

    public void ˏ(byte[] bArr) throws IOException {
        try {
            ˎ((long) bArr.length);
            this.ˋ.ˏ(bArr);
        } catch (EOFException e) {
            EOFException eOFException = e;
            int i = 0;
            while (this.ˋ.ˎ > 0) {
                int ˎ = this.ˋ.ˎ(bArr, i, (int) this.ˋ.ˎ);
                if (ˎ == -1) {
                    throw new AssertionError();
                }
                i += ˎ;
            }
            throw eOFException;
        }
    }

    public int read(ByteBuffer byteBuffer) throws IOException {
        if (this.ˋ.ˎ == 0 && this.ˊ.ˊ(this.ˋ, 8192) == -1) {
            return -1;
        }
        return this.ˋ.read(byteBuffer);
    }

    public String ˏ(Charset charset) throws IOException {
        if (charset == null) {
            throw new IllegalArgumentException("charset == null");
        }
        this.ˋ.ˋ(this.ˊ);
        return this.ˋ.ˏ(charset);
    }

    public String ॱˋ() throws IOException {
        return ˊ(Long.MAX_VALUE);
    }

    public String ˊ(long j) throws IOException {
        if (j < 0) {
            throw new IllegalArgumentException("limit < 0: " + j);
        }
        long j2 = j == Long.MAX_VALUE ? Long.MAX_VALUE : j + 1;
        long ˋ = ˋ((byte) 10, 0, j2);
        if (ˋ != -1) {
            return this.ˋ.ᐝ(ˋ);
        }
        if (j2 < Long.MAX_VALUE && ॱ(j2) && this.ˋ.ॱ(j2 - 1) == (byte) 13 && ॱ(1 + j2) && this.ˋ.ॱ(j2) == (byte) 10) {
            return this.ˋ.ᐝ(j2);
        }
        fxi o_fxi = new fxi();
        this.ˋ.ˊ(o_fxi, 0, Math.min(32, this.ˋ.ॱ()));
        throw new EOFException("\\n not found: limit=" + Math.min(this.ˋ.ॱ(), j) + " content=" + o_fxi.ॱˎ().ᐝ() + '…');
    }

    public short ॱˊ() throws IOException {
        ˎ(2);
        return this.ˋ.ॱˊ();
    }

    public short ˊॱ() throws IOException {
        ˎ(2);
        return this.ˋ.ˊॱ();
    }

    public int ˋॱ() throws IOException {
        ˎ(4);
        return this.ˋ.ˋॱ();
    }

    public int ˏॱ() throws IOException {
        ˎ(4);
        return this.ˋ.ˏॱ();
    }

    public long ͺ() throws IOException {
        ˎ(1);
        int i = 0;
        while (ॱ((long) (i + 1))) {
            byte ॱ = this.ˋ.ॱ((long) i);
            if ((ॱ < (byte) 48 || ॱ > (byte) 57) && !(i == 0 && ॱ == (byte) 45)) {
                if (i == 0) {
                    throw new NumberFormatException(String.format("Expected leading [0-9] or '-' character but was %#x", new Object[]{Byte.valueOf(ॱ)}));
                }
                return this.ˋ.ͺ();
            }
            i++;
        }
        return this.ˋ.ͺ();
    }

    public long ᐝॱ() throws IOException {
        ˎ(1);
        for (int i = 0; ॱ((long) (i + 1)); i++) {
            byte ॱ = this.ˋ.ॱ((long) i);
            if ((ॱ < (byte) 48 || ॱ > (byte) 57) && ((ॱ < (byte) 97 || ॱ > (byte) 102) && (ॱ < (byte) 65 || ॱ > (byte) 70))) {
                if (i == 0) {
                    throw new NumberFormatException(String.format("Expected leading [0-9a-fA-F] character but was %#x", new Object[]{Byte.valueOf(ॱ)}));
                }
                return this.ˋ.ᐝॱ();
            }
        }
        return this.ˋ.ᐝॱ();
    }

    public void ʼ(long j) throws IOException {
        if (this.ॱ) {
            throw new IllegalStateException("closed");
        }
        while (j > 0) {
            if (this.ˋ.ˎ == 0 && this.ˊ.ˊ(this.ˋ, 8192) == -1) {
                throw new EOFException();
            }
            long min = Math.min(j, this.ˋ.ॱ());
            this.ˋ.ʼ(min);
            j -= min;
        }
    }

    public long ॱ(byte b) throws IOException {
        return ˋ(b, 0, Long.MAX_VALUE);
    }

    public long ˋ(byte b, long j, long j2) throws IOException {
        if (this.ॱ) {
            throw new IllegalStateException("closed");
        } else if (j < 0 || j2 < j) {
            throw new IllegalArgumentException(String.format("fromIndex=%s toIndex=%s", new Object[]{Long.valueOf(j), Long.valueOf(j2)}));
        } else {
            long j3 = j;
            while (j3 < j2) {
                long ˋ = this.ˋ.ˋ(b, j3, j2);
                if (ˋ != -1) {
                    return ˋ;
                }
                ˋ = this.ˋ.ˎ;
                if (ˋ >= j2 || this.ˊ.ˊ(this.ˋ, 8192) == -1) {
                    return -1;
                }
                j3 = Math.max(j3, ˋ);
            }
            return -1;
        }
    }

    public boolean ˋ(long j, fxh o_fxh) throws IOException {
        return ˎ(j, o_fxh, 0, o_fxh.ʼ());
    }

    public boolean ˎ(long j, fxh o_fxh, int i, int i2) throws IOException {
        if (this.ॱ) {
            throw new IllegalStateException("closed");
        } else if (j < 0 || i < 0 || i2 < 0 || o_fxh.ʼ() - i < i2) {
            return false;
        } else {
            int i3 = 0;
            while (i3 < i2) {
                long j2 = ((long) i3) + j;
                if (!ॱ(1 + j2) || this.ˋ.ॱ(j2) != o_fxh.ˏ(i + i3)) {
                    return false;
                }
                i3++;
            }
            return true;
        }
    }

    public InputStream ʽ() {
        return new InputStream(this) {
            final /* synthetic */ fxp ˋ;

            {
                this.ˋ = r1;
            }

            public int read() throws IOException {
                if (this.ˋ.ॱ) {
                    throw new IOException("closed");
                } else if (this.ˋ.ˋ.ˎ == 0 && this.ˋ.ˊ.ˊ(this.ˋ.ˋ, 8192) == -1) {
                    return -1;
                } else {
                    return this.ˋ.ˋ.ʻ() & 255;
                }
            }

            public int read(byte[] bArr, int i, int i2) throws IOException {
                if (this.ˋ.ॱ) {
                    throw new IOException("closed");
                }
                fxy.ˊ((long) bArr.length, (long) i, (long) i2);
                if (this.ˋ.ˋ.ˎ == 0 && this.ˋ.ˊ.ˊ(this.ˋ.ˋ, 8192) == -1) {
                    return -1;
                }
                return this.ˋ.ˋ.ˎ(bArr, i, i2);
            }

            public int available() throws IOException {
                if (!this.ˋ.ॱ) {
                    return (int) Math.min(this.ˋ.ˋ.ˎ, 2147483647L);
                }
                throw new IOException("closed");
            }

            public void close() throws IOException {
                this.ˋ.close();
            }

            public String toString() {
                return this.ˋ + ".inputStream()";
            }
        };
    }

    public boolean isOpen() {
        return !this.ॱ;
    }

    public void close() throws IOException {
        if (!this.ॱ) {
            this.ॱ = true;
            this.ˊ.close();
            this.ˋ.ʿ();
        }
    }

    public fxv ˊ() {
        return this.ˊ.ˊ();
    }

    public String toString() {
        return "buffer(" + this.ˊ + ")";
    }
}
